package com.lifeng.common.util;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;
/**
 * @author: lifeng
 * @description:后端返回统一的结果
 **/
@Data
public class Result {
	private Integer code;
	private String message;
	private Map<String,Object> data = new HashMap<>();

	//成功时调用
	public static Result ok(){
		Result result = new Result();
		result.setCode(200);
		result.setMessage("操作成功！");
		return result;
	}
	//失败时调用
	public static Result error(){
		Result result = new Result();
		result.setCode(500);
		result.setMessage("操作失败！");
		return result;
	}

	//出错信息
	public Result message(String message){
		this.setMessage(message);
		return this;
	}
	//lifeng
	//出错码
	public Result code(Integer code){
		this.setCode(code);
		return this;
	}
	//lifeng
	//单个数据
	public Result data(String key, Object value){
		this.data.put(key,value);
		return this;
	}
	//lifeng
	//map设置数据
	public Result data(Map<String,Object> map){
		this.setData(map);
		return this;
	}

}
